import request from '@/utils/request'

export function getOrderList(msg) {
	let query = new FormData();
	query.append("status", msg.status);
	query.append("orderType", msg.orderType);
	query.append("warehouseIds", msg.warehouseIds);
	query.append("pageNum", msg.pageNum);
	query.append("pageSize", msg.pageSize);
	if (msg.deliveryType != undefined) {
		query.append('deliveryType', msg.deliveryType);
	}
	if (msg.receiverPhone != undefined) {
		query.append('receiverPhone', msg.receiverPhone);
	}
	if (msg.productName != undefined) {
		query.append('productName', msg.productName);
	}
	if (msg.orderSn != undefined) {
		query.append('orderSn', msg.orderSn);
	}
	if (msg.memberUsername != undefined) {
		query.append('memberUsername', msg.memberUsername);
	}
	if (msg.startTime != undefined) {
		query.append('startTime', msg.startTime);
		query.append('endTime', msg.endTime);
	}
	return request({
		headers: {
			"Content-Type": "multipart/form-data"
		},
		url: "/order/list",
		method: "POST",
		data: query
	})
}

export function getOrderDetail(id) {
	return request({
		url: `/order/detail/${id}`,
		method: "GET"
	})
}

export function getServiceOrderDetail(id) {
	return request({
		url: `/order/server/detail/${id}`,
		method: "GET"
	})
}

export function deliverOrder(form) {
	let query = new FormData();
	if (form.warehouseId != undefined) {
		query.append("warehouseId", form.warehouseId)
	}
	if (form.deliveryId != undefined) {
		query.append("deliveryId", form.deliveryId)
	}
	return request({
		headers: {
			"Content-Type": "multipart/form-data"
		},
		url: `/order/deliver/${form.orderId}`,
		method: "POSt",
		data: query
	})
}

export function cancelOrder(id) {
	return request({
		url: `/order/cancel/${id}`,
		method: "GET"
	})
}

export function completeOrder(id) {
	return request({
		url: `/order/complete/${id}`,
		method: "GET"
	})
}

export function getSlraiOrderList(query, page) {
	return request({
		url: "/return/apply/list",
		method: "POST",
		params: page,
		data: query
	})
}

export function getSlraiOrderDetail(id) {
	return request({
		url: `/return/apply/detail/${id}`,
		method: "GET"
	})
}

export function handleSlraiOrderAgree(id, count) {
	let query = {
		realReturnAmount: count
	}
	return request({
		url: `/return/apply/agree/${id}`,
		method: "GET",
		params: query
	})
}

export function handleSlraiOrderRefuse(id) {
	return request({
		url: `/return/apply/refuse/${id}`,
		method: "POST"
	})
}

export function handleSlraiOrderRefund(id) {
	return request({
		url: `/return/apply/refund/${id}`,
		method: "GET"
	})
}

export function updatePayAmount(msg) {
	let query = new FormData();
	query.append('orderId',msg.orderId);
	query.append('payAmount',msg.payAmount);
	return request({
		headers: {
			"Content-Type": "multipart/form-data"
		},
		url: `/order/modify/payAmount`,
		method: "POST",
		data: query
	})
}
